//
//  CCMHomeViewCell.swift
//  CCMoney_swift
//
//  Created by JKHuang on 2018/11/26.
//  Copyright © 2018 JKHuang. All rights reserved.
//

import UIKit

class CCMHomeViewCell: UITableViewCell {
    
    lazy var lineView:UIView = {
        
        let view = UIView()
        view.backgroundColor = UIColor.hex(0xD9D9D9)
        return view
    }()
    
    fileprivate lazy var orderLabel:UILabel = {
        
        let label = UILabel()
        label.font = UIFont.systemFont(ofSize: 14)
        label.textColor = UIColor.white
        return label
    }()
    
    fileprivate lazy var timeLabel:UILabel = {
        
        let label = UILabel()
        label.font = UIFont.systemFont(ofSize: 14)
        label.textColor = UIColor.white
        return label
    }()

    fileprivate lazy var headView:UIImageView = {
       
        let image = UIImageView ()
        image.contentMode = .scaleAspectFill
        image.clipsToBounds = true
        image.layer.cornerRadius = 20.0
        image.clipsToBounds = true
        return image
    }()
    
    fileprivate lazy var nameLabel:UILabel = {
        
        let label = UILabel()
        label.font = UIFont.systemFont(ofSize: 15)
        label.textColor = UIColor.white
        return label
    }()
    
    fileprivate lazy var getMoneyLabel:UILabel = {
        
        let label = UILabel()
        label.font = UIFont.systemFont(ofSize: 14)
        label.textColor = UIColor.white
        return label
    }()
    
    fileprivate lazy var getMoneyLabel1:UILabel = {
        
        let label = UILabel()
        label.font = UIFont.systemFont(ofSize: 14)
        label.textColor = UIColor.white
        return label
    }()
    
    fileprivate lazy var phoneLabel:UILabel = {
        
        let label = UILabel()
        label.textColor = UIColor.hex(0xEEEEEE)
        label.font = UIFont.systemFont(ofSize: 12)
        return label
    }()
    
    fileprivate lazy var sureOrderBut:UIButton = {
        let button = UIButton()
        button.setTitle("确认订单", for: .normal)
        button.setTitleColor(UIColor.white, for: .normal)
        button.layer.cornerRadius = 15
        button.backgroundColor = UIColor.red
        button.clipsToBounds = true
        button.titleLabel?.font = UIFont.systemFont(ofSize: 14)
        return button
    }()
    
    fileprivate lazy var passTimeLabel:UILabel = {
        let label = UILabel()
        label.font = UIFont.systemFont(ofSize: 14)
        label.textColor = UIColor.white
        return label
    }()
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        setUI()
        
        self.orderLabel.text = "订单:567897654345678987654"
        self.headView.image = UIImage(named:"头像_iocn")
        self.nameLabel.text = "大西瓜addddd"
        self.timeLabel.text = "2018-11-12 12:33"
        self.passTimeLabel.text = "距超时仅剩:20:22:11"
        
//        let sTring = "全新上市 "
//        let moneyString = "￥300元"
//        let attrString = NSMutableAttributedString(string: "全新上市 ￥300元")
//        attrString.setAttributes([NSAttributedString.Key.font:UIFont.systemFont(ofSize: 16),NSAttributedString.Key.foregroundColor: UIColor.hex(0xEF9C05)], range: NSMakeRange(sTring.count, moneyString.count))

        self.phoneLabel.text = "电话:13800138000"
        self.getMoneyLabel.text = "可得利润"
        self.getMoneyLabel1.text = "￥100"
//        self.priceLabel.text = "全新上市 ￥300元"
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

}

extension CCMHomeViewCell{
    
    fileprivate func setUI(){
        
        self.contentView.addSubview(self.orderLabel)
        self.contentView.addSubview(self.timeLabel)
        self.contentView.addSubview(self.headView)
        self.contentView.addSubview(self.nameLabel)
        self.contentView.addSubview(self.phoneLabel)
        self.contentView.addSubview(self.lineView)
        self.contentView.addSubview(self.getMoneyLabel)
        self.contentView.addSubview(self.getMoneyLabel1)
        self.contentView.addSubview(self.sureOrderBut)
        self.contentView.addSubview(self.passTimeLabel)
        
        self.orderLabel.snp.makeConstraints { (make) in
            make.top.equalTo(self.contentView).offset(10)
            make.leading.equalTo(self.contentView).offset(15)
        }
        
        self.timeLabel.snp.makeConstraints { (make) in
            make.top.equalTo(self.contentView).offset(10)
            make.trailing.equalTo(self.contentView).offset(-15)
        }
        
        self.headView.snp.makeConstraints { (make) in
            make.top.equalTo(self.orderLabel.snp.bottom).offset(10)
            make.leading.equalTo(self.contentView).offset(15)
            make.height.width.equalTo(71)
        }
        
        self.nameLabel.snp.makeConstraints { (make) in
            make.top.equalTo(self.headView).offset(10)
            make.leading.equalTo(self.headView.snp.trailing).offset(10)
        }
        
        self.getMoneyLabel.snp.makeConstraints { (make) in
            
            make.top.equalTo(self.headView).offset(10)
            make.trailing.equalTo(self.contentView).offset(-15)
        }
        
        self.phoneLabel.snp.makeConstraints { (make) in
            make.top.equalTo(self.nameLabel.snp.bottom).offset(10)
            make.leading.equalTo(self.headView.snp.trailing).offset(10)
        }
        
        self.getMoneyLabel1.snp.makeConstraints { (make) in
            
            make.top.equalTo(self.nameLabel.snp.bottom).offset(10)
            make.trailing.equalTo(self.contentView).offset(-15)
        }
        
        self.lineView.snp.makeConstraints { (make) in
            make.bottom.equalTo(self.contentView)
            make.leading.equalTo(self.contentView)
            make.trailing.equalTo(self.contentView)
            make.height.equalTo(0.8)
        }
        
        self.sureOrderBut.snp.makeConstraints { (make) in
            make.bottom.equalTo(self.contentView).offset(-15)
            make.trailing.equalTo(self.contentView).offset(-15)
            make.width.equalTo(75)
            make.height.equalTo(30)
        }
        
        self.passTimeLabel.snp.makeConstraints { (make) in
            make.centerY.equalTo(self.sureOrderBut)
            make.trailing.equalTo(self.sureOrderBut.snp.leading).offset(-20);
        }
    }
}
